home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / jaq / dist / dev.c.dummy < prev    next >
Encoding:
Text File  |  1992-10-26  |  11.4 KB  |  598 lines

  1. /* 
  2.  * dev.c--
  3.  *
  4.  *    Device-dependent manipulations
  5.  *
  6.  * Copyright 1991 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * Quote:
  16.  *      "What a depressingly stupid machine"
  17.  *      -- Marvin in _A Hitchiker's Guide to the Galaxy_
  18.  *
  19.  */
  20.  
  21. #ifndef lint
  22. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/dev.c,v 1.0 91/01/07 18:02:37 mottsmth Exp $ SPRITE (Berkeley)";
  23. #endif /* not lint */
  24.  
  25. #include <stdio.h>
  26. #include <sys/types.h>
  27. #include <sys/mtio.h>
  28. #include "jaquith.h"
  29.  
  30. typedef struct mtop Dev_TapeCommand;
  31.  
  32. static char printBuf[T_MAXSTRINGLEN];
  33. extern int syserr;
  34.  
  35.  
  36. /*
  37.  *----------------------------------------------------------------------
  38.  *
  39.  * Dev_MoveVolume --
  40.  *
  41.  *    Move a volume from source slot to destination slot in jukebox
  42.  *
  43.  * Results:
  44.  *    Ptr to block of specified size or NULL;
  45.  *
  46.  * Side effects:
  47.  *    Moves robot arm. May also affect volume reader.
  48.  *
  49.  * Note:
  50.  *      The tape reader devices in the EXB-120 jukebox are given slot
  51.  *      numbers 116-119. If one of these is the destination address
  52.  *      a tape load is effectively done.  
  53.  *
  54.  *----------------------------------------------------------------------
  55.  */
  56.  
  57. int
  58. Dev_MoveVolume(robotStream, src, dest)
  59.     int robotStream;          /* robot file descriptor */
  60.     int src;                  /* source location */
  61.     int dest;                 /* destination location */
  62. {
  63.  
  64.     return T_SUCCESS;
  65.  
  66. }
  67.  
  68.  
  69.  
  70. /*
  71.  *----------------------------------------------------------------------
  72.  *
  73.  * Dev_OpenVolume --
  74.  *
  75.  *    Open the device
  76.  *
  77.  * Results:
  78.  *    return code
  79.  *
  80.  * Side effects:
  81.  *    None.
  82.  *
  83.  *----------------------------------------------------------------------
  84.  */
  85.  
  86. int
  87. Dev_OpenVolume(devName, flags)
  88.     char *devName;            /* name of device */
  89.     int flags;                /* read, write etc. flags */
  90. {
  91.     int fd;
  92.  
  93.     if ((fd=open(devName, flags, 0)) == -1) {
  94.     syserr = errno;
  95.     }
  96.     return fd;
  97. }
  98.  
  99.  
  100. /*
  101.  *----------------------------------------------------------------------
  102.  *
  103.  * Dev_CloseVolume --
  104.  *
  105.  *    Close the device
  106.  *
  107.  * Results:
  108.  *    return code
  109.  *
  110.  * Side effects:
  111.  *    None.
  112.  *
  113.  *----------------------------------------------------------------------
  114.  */
  115.  
  116. int
  117. Dev_CloseVolume(stream)
  118.     int stream;               /* file descriptor */
  119. {
  120.     if (close(stream) == -1) {
  121.     syserr = errno;
  122.     return T_FAILURE;
  123.     } else {
  124.     return T_SUCCESS;
  125.     }
  126. }
  127.  
  128.  
  129. /*
  130.  *----------------------------------------------------------------------
  131.  *
  132.  * Dev_ReadVolume --
  133.  *
  134.  *    Perform read operation on volume.
  135.  *
  136.  * Results:
  137.  *    return code
  138.  *
  139.  * Side effects:
  140.  *    None.
  141.  *
  142.  *----------------------------------------------------------------------
  143.  */
  144.  
  145. int
  146. Dev_ReadVolume(volStream, buf, bufSize)
  147.     int volStream;
  148.     char *buf;
  149.     int bufSize;
  150. {
  151.     int cnt;
  152.  
  153.     if ((cnt=read(volStream, buf, bufSize)) < 0) {
  154.     syserr = errno;
  155.     }
  156.     return cnt;
  157. }
  158.  
  159.  
  160. /*
  161.  *----------------------------------------------------------------------
  162.  *
  163.  * Dev_WriteVolume --
  164.  *
  165.  *    Perform write operation on volume.
  166.  *
  167.  * Results:
  168.  *    return code
  169.  *
  170.  * Side effects:
  171.  *    None.
  172.  *
  173.  *----------------------------------------------------------------------
  174.  */
  175.  
  176. int
  177. Dev_WriteVolume(volStream, buf, bufSize)
  178.     int volStream;
  179.     char *buf;
  180.     int bufSize;
  181. {
  182.     int cnt;
  183.  
  184.     if ((cnt=write(volStream, buf, bufSize)) < 0) {
  185.     syserr = errno;
  186.     }
  187.     return cnt;
  188. }
  189.  
  190.  
  191. /*
  192.  *----------------------------------------------------------------------
  193.  *
  194.  * Dev_UnloadVolume --
  195.  *
  196.  *    Open the pod bay door. I'm sorry I can't do that Dave.
  197.  *
  198.  * Results:
  199.  *    return code
  200.  *
  201.  * Side effects:
  202.  *    Moves robot arm. May also affect volume reader.
  203.  *
  204.  *----------------------------------------------------------------------
  205.  */
  206.  
  207. int
  208. Dev_UnloadVolume(devName)
  209.     char *devName;            /* device name */
  210. {
  211.     int volStream;
  212.     Dev_TapeCommand tapeCmd;
  213.  
  214.     if ((volStream=open(devName, O_RDONLY, 0)) < 0) {
  215.     syserr = errno;
  216.     return T_FAILURE;
  217.     }
  218.     
  219.     tapeCmd.mt_op = MTOFFL;
  220.     tapeCmd.mt_count = 1;
  221.  
  222.     if (ioctl(volStream, MTIOCTOP, (char *)&tapeCmd) != 0) {
  223.     syserr = errno;
  224.         close(volStream);
  225.     return T_FAILURE;
  226.     }
  227.     close(volStream);
  228.  
  229.     return T_SUCCESS;
  230.  
  231. }
  232.  
  233. /*
  234.  *----------------------------------------------------------------------
  235.  *
  236.  * Dev_InitRobot --
  237.  *
  238.  *    Initialize robot.
  239.  *
  240.  * Results:
  241.  *    return code
  242.  *
  243.  * Side effects:
  244.  *    Instructs robot to build database of volume id's
  245.  *      using barcode reader.
  246.  *
  247.  * Note:
  248.  *      At the moment 'initialization' this means taking 
  249.  *      tape inventory.
  250.  *      
  251.  *----------------------------------------------------------------------
  252.  */
  253.  
  254. int
  255. Dev_InitRobot(robotStream)
  256.     int robotStream;          /* robot descriptor */
  257. {
  258.  
  259.     return T_SUCCESS;
  260.  
  261. }
  262.  
  263.  
  264. /*
  265.  *----------------------------------------------------------------------
  266.  *
  267.  * Dev_ReadVolLabel --
  268.  *
  269.  *    Read volume label with barcode reader
  270.  *
  271.  * Results:
  272.  *    return code
  273.  *
  274.  * Side effects:
  275.  *    Instructs robot to return element status from its database.
  276.  *
  277.  *----------------------------------------------------------------------
  278.  */
  279.  
  280. int
  281. Dev_ReadVolLabel(robotStream, location, volLabel)
  282.     int robotStream;          /* robot descriptor */
  283.     int location;             /* home slot in jukebox */
  284.     char *volLabel;           /* receiving space for volume label */
  285. {
  286.  
  287.     return T_SUCCESS;
  288.  
  289. }
  290.  
  291.  
  292. /*
  293.  *----------------------------------------------------------------------
  294.  *
  295.  * Dev_CvtVolLabel --
  296.  *
  297.  *    Convert character volume label to unique integer.
  298.  *
  299.  * Results:
  300.  *    return code
  301.  *
  302.  * Side effects:
  303.  *    None.
  304.  *
  305.  * Note:
  306.  *      For present purposes, labels are of the form "<text><number>"
  307.  *
  308.  *----------------------------------------------------------------------
  309.  */
  310.  
  311. int
  312. Dev_CvtVolLabel(volLabel)
  313.     char *volLabel;
  314. {
  315.     int volId;
  316.     char *workPtr = volLabel+strlen(volLabel)-1;
  317.  
  318.     while ((workPtr >= volLabel) && (isdigit(*workPtr))) {
  319.     workPtr--;
  320.     }
  321.     if ((workPtr >= volLabel) && (sscanf(workPtr+1, "%d", &volId) == 1)) {
  322.     return volId;
  323.     } else {
  324.     return -1;
  325.     }
  326. }
  327.  
  328.  
  329.  
  330.  
  331. /*
  332.  *----------------------------------------------------------------------
  333.  *
  334.  * Dev_SeekVolume --
  335.  *
  336.  *    Seek to file marker
  337.  *
  338.  * Results:
  339.  *    return code
  340.  *
  341.  * Side effects:
  342.  *    Instructs tape to seek
  343.  *
  344.  *----------------------------------------------------------------------
  345.  */
  346.  
  347. int
  348. Dev_SeekVolume(volStream, blkId, absolute)
  349.     int volStream;            /* volume descriptor */
  350.     int blkId;                /* logical file num */
  351.     int absolute;             /* absolute positioning flag */
  352. {
  353.     int status;
  354.     Dev_TapeCommand tapeCmd;
  355.     int oldOffset = 0;
  356.     int retryCnt = 0;
  357.  
  358.     if ((blkId < 0) || (blkId > 10000)) {
  359.     fprintf(stderr,"Dev_SeekVolume: Bad blkId: %d\n", blkId);
  360.     }
  361.  
  362.     if ((volStream < 0) || (volStream > 20)) {
  363.     fprintf(stderr,"Dev_SeekVolume: Bad volStream: %d\n", volStream);
  364.     }
  365.  
  366.     if (absolute) {
  367.     tapeCmd.mt_op = MTREW;
  368.     tapeCmd.mt_count = 1;
  369.     status = ioctl(volStream, MTIOCTOP, (char *)&tapeCmd);
  370.     while ((retryCnt++ < 5) && (status != 0)) {
  371.         fprintf(stderr, "Rewind failed: errno %d. Retrying...\n",
  372.             errno);
  373.         sleep(2);
  374.         status = ioctl(volStream, MTIOCTOP, (char *)&tapeCmd);
  375.     }
  376.     if (status != 0) {
  377.         syserr = errno;
  378.         fprintf(stderr, "Couldn't rewind tape. errno %d\n",syserr);
  379.         return T_IOFAILED;
  380.     }
  381.     }
  382.  
  383.     if (blkId > 0) {
  384.     tapeCmd.mt_op = MTFSF;
  385.     tapeCmd.mt_count = blkId;
  386.     status = ioctl(volStream, MTIOCTOP, (char *)&tapeCmd);
  387.     if (status != 0) {
  388.         syserr = errno;
  389.         fprintf(stderr, "Couldn't skip %d files: %d\n",
  390.             blkId, syserr);
  391.         return T_IOFAILED;
  392.     }
  393.     }
  394.  
  395.     return T_SUCCESS;
  396. }
  397.  
  398.  
  399.  
  400. /*
  401.  *----------------------------------------------------------------------
  402.  *
  403.  * Dev_WriteEOF --
  404.  *
  405.  *    write out EOF
  406.  *
  407.  * Results:
  408.  *    return code
  409.  *
  410.  * Side effects:
  411.  *    Puts file marker on tape
  412.  *
  413.  *----------------------------------------------------------------------
  414.  */
  415.  
  416. int
  417. Dev_WriteEOF(volStream, count)
  418.     int volStream;            /* active stream */
  419.     int count;                /* number of marks to write */
  420. {
  421.     int status;
  422.     Dev_TapeCommand tapeCmd;
  423.  
  424.     tapeCmd.mt_op = MTWEOF;
  425.     tapeCmd.mt_count = count;
  426.  
  427.     status = ioctl(volStream, MTIOCTOP, (char *)&tapeCmd);
  428.  
  429.     if (status == 0) {
  430.     return T_SUCCESS;
  431.     } else {
  432.     syserr = errno;
  433.     return T_IOFAILED;
  434.     }
  435. }
  436.  
  437.  
  438.  
  439. /*
  440.  *----------------------------------------------------------------------
  441.  *
  442.  * Dev_GetVolStatus --
  443.  *
  444.  *    Inquire into state of volume device
  445.  *
  446.  * Results:
  447.  *    return code
  448.  *
  449.  * Side effects:
  450.  *    None.
  451.  *
  452.  *----------------------------------------------------------------------
  453.  */
  454.  
  455. int
  456. Dev_GetVolStatus(volStream, volStatusPtr)
  457.     int volStream;            /* volume descriptor */
  458.     VolStatus *volStatusPtr;  /* receiving structure */
  459. {
  460.  
  461.     volStatusPtr->position = -1;
  462.     return T_SUCCESS;
  463. }
  464.  
  465. /*
  466.  *----------------------------------------------------------------------
  467.  *
  468.  * Dev_DisplayMsg --
  469.  *
  470.  *    Display message on jukebox screen
  471.  *
  472.  * Results:
  473.  *    return code
  474.  *
  475.  * Side effects:
  476.  *    None.
  477.  *
  478.  *----------------------------------------------------------------------
  479.  */
  480.  
  481. int
  482. Dev_DisplayMsg(robotStream, msg, msgStyle)
  483.     int robotStream;          /* volume descriptor */
  484.     char *msg;                /* Message text */
  485.     int msgStyle;             /* 0==Steady, 1==flash, 2==scroll */
  486. {
  487.  
  488.     return T_SUCCESS;
  489.  
  490. }
  491.  
  492.  
  493. /*
  494.  *----------------------------------------------------------------------
  495.  *
  496.  * Dev_OpenDoor --
  497.  *
  498.  *    Open (or at least unlock) the jukebox door.
  499.  *
  500.  * Results:
  501.  *    return code
  502.  *
  503.  * Side effects:
  504.  *    None.
  505.  *
  506.  *----------------------------------------------------------------------
  507.  */
  508.  
  509. int
  510. Dev_OpenDoor(robotStream)
  511.     int robotStream;          /* robot descriptor */
  512.     return T_SUCCESS;
  513. }
  514.  
  515.  
  516. /*
  517.  *----------------------------------------------------------------------
  518.  *
  519.  * Dev_RemoveVolume --
  520.  *
  521.  *    Open (or at least unlock) the jukebox door.
  522.  *
  523.  * Results:
  524.  *    return code
  525.  *
  526.  * Side effects:
  527.  *    Kicks a volume out of archive.
  528.  *
  529.  *----------------------------------------------------------------------
  530.  */
  531.  
  532. int
  533. Dev_RemoveVolume(robotStream, src)
  534.     int robotStream;          /* robot descriptor */
  535.     int src;                  /* src slot location */
  536.  
  537.     return T_SUCCESS;
  538.  
  539. }
  540.  
  541.  
  542. /*
  543.  *----------------------------------------------------------------------
  544.  *
  545.  * Dev_InsertVolume --
  546.  *
  547.  *    Open (or at least unlock) the jukebox door.
  548.  *
  549.  * Results:
  550.  *    return code
  551.  *
  552.  * Side effects:
  553.  *    Pull in a new volume.
  554.  *
  555.  *----------------------------------------------------------------------
  556.  */
  557.  
  558. int
  559. Dev_InsertVolume(robotStream, dest)
  560.     int robotStream;          /* robot descriptor */
  561.     int dest;                 /* destination slot location */
  562.  
  563.     return T_SUCCESS;
  564.  
  565. }
  566.  
  567. /*
  568.  *----------------------------------------------------------------------
  569.  *
  570.  * Dev_BuildVolList --
  571.  *
  572.  *    Build a list of jukebox's contents
  573.  *
  574.  * Results:
  575.  *    return code
  576.  *
  577.  * Side effects:
  578.  *    none.
  579.  *
  580.  *----------------------------------------------------------------------
  581.  */
  582.  
  583. int
  584. Dev_BuildVolList(robotStream, listPtr, cntPtr)
  585.     int robotStream;          /* robot descriptor */
  586.     VolConfig *listPtr;       /* space for volume info */
  587.     int *cntPtr;              /* size of list */
  588.                 
  589.     *cntPtr = 0;
  590.     return T_SUCCESS;
  591.  
  592. }
  593.  
  594.